package com.team.abs.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import com.team.abs.service.loginserviceimpl;
import com.team.abs.service.registerserviceimpl;
@RequestMapping("/pipi")
@Controller
public class logincontroller {
	@Autowired
	private loginserviceimpl loginserviceimpl;
	@Autowired
	private registerserviceimpl registerserviceimpl;

	@RequestMapping("/login")
	public String dologin() {
		return "login";
	}
	@RequestMapping(value="/userlogin",method=RequestMethod.POST)
	public ResponseEntity<String>login(
			@RequestParam(value="username")String username,
			@RequestParam(value="password")String password){
		int res=loginserviceimpl.login(username, password);
		//System.out.println(username+" "+password);
		//System.out.println(res);
			return ResponseEntity.ok(String.valueOf(res));
	}
	@RequestMapping(value="/register",method = RequestMethod.POST)
	public ResponseEntity<String>regiser(
		@RequestParam(value="username")String username,
		@RequestParam(value = "password")String password){
			//System.out.println("register");
			int res=registerserviceimpl.register(username, password);
			if(res==-1){
				ResponseEntity.ok("000");
			}

			return ResponseEntity.ok(String.valueOf(res));
		}
	
}
